{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# NONE-EARLY All RIDERS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import_and_maybe_install <- function(pkgs){\n",
    "    missing_packages <- character(0)\n",
    "    for(pkg in pkgs){\n",
    "        tryCatch({\n",
    "            require(pkg, character.only=TRUE )\n",
    "        },warning=function(err){\n",
    "            missing_packages <<- c(missing_packages,pkg)\n",
    "        })\n",
    "    }\n",
    "    if(length(missing_packages)){\n",
    "            install.packages(missing_packages)\n",
    "            sapply(missing_packages, require, character.only=TRUE)\n",
    "    }\n",
    "    invisible(NULL)\n",
    "}\n",
    "import_and_maybe_install(c(\"data.table\", \"feather\", \"ggplot2\",\"clusterSEs\",\"formula.tools\",\"estimatr\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "DATA_DIR <- \"~/connector/20200226/analytic_datasets\"\n",
    "\n",
    "commute_ride_data <- read_feather( file.path(DATA_DIR,\"commute_ride_data.feather\"))\n",
    "setDT(commute_ride_data)\n",
    "\n",
    "# FACTOR VARIABLES\n",
    "stopifnot(commute_ride_data[,class(fAid) == \"factor\"]) # rider id\n",
    "stopifnot(commute_ride_data[,class(fDate) == \"factor\"]) # date id\n",
    "\n",
    "route_field <- sprintf(\"route_%s_10_ride\",1:21)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### FILTER on {{NOT}} EARLY RIDERS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of Early Riders"
     ]
    },
    {
     "data": {
      "text/html": [
       "3908"
      ],
      "text/latex": [
       "3908"
      ],
      "text/markdown": [
       "3908"
      ],
      "text/plain": [
       "[1] 3908"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Full Data"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>Records</th><th scope=col>Rides</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>3354470</td><td>805199 </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ll}\n",
       " Records & Rides\\\\\n",
       "\\hline\n",
       "\t 3354470 & 805199 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| Records | Rides |\n",
       "|---|---|\n",
       "| 3354470 | 805199  |\n",
       "\n"
      ],
      "text/plain": [
       "  Records Rides \n",
       "1 3354470 805199"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Late riders only"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>Records</th><th scope=col>Rides</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>1562314</td><td>164677 </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|ll}\n",
       " Records & Rides\\\\\n",
       "\\hline\n",
       "\t 1562314 & 164677 \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| Records | Rides |\n",
       "|---|---|\n",
       "| 1562314 | 164677  |\n",
       "\n"
      ],
      "text/plain": [
       "  Records Rides \n",
       "1 1562314 164677"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "dates = commute_ride_data[,.N,keyby=.(date,fDate)]\n",
    "MAX_DATE = dates[15,date]\n",
    "\n",
    "early_riders = commute_ride_data[date <= MAX_DATE & did_ride,1,keyby=aid][,V1:=NULL]\n",
    "cat(\"Number of Early Riders\")\n",
    "early_riders[,.N]\n",
    "\n",
    "setkey(commute_ride_data,aid)\n",
    "late_rider_data = commute_ride_data[!early_riders]\n",
    "\n",
    "cat(\"Full Data\")\n",
    "commute_ride_data[,.(Records=.N,Rides=sum(did_ride))]\n",
    "\n",
    "cat(\"Late riders only\")\n",
    "late_rider_data[,.(Records=.N,Rides=sum(did_ride))]\n",
    "\n",
    "commute_ride_data = late_rider_data\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# CALCULATE FAVORITE ROUTE\n",
    "commute_ride_data$favorite_route <- apply(\n",
    "    as.matrix(commute_ride_data[,sprintf(\"route_%s_10_ride\",1:21),with=FALSE]),\n",
    "    1,\n",
    "    function(x){\n",
    "        routes = which(x == max(x))\n",
    "        if(length(routes) == 1){\n",
    "            routes\n",
    "        }else{\n",
    "            sample(routes,1)\n",
    "        }\n",
    "    })\n",
    "\n",
    "commute_ride_data[, f_favorite_route:= as.factor(favorite_route) ]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Data Dictionary\n",
    "\n",
    "Each record represents one rider commute opportunty (rider / date / commute).\n",
    "\n",
    "**Note that** there is one record for each commute / data for every rider \n",
    "*After their first ride date*.  This is because the choice to ride (`did_ride`) \n",
    "is conditioned on the rider's history of riding, and which is not available \n",
    "on thier first ride.\n",
    "\n",
    "#### Identifiers\n",
    "* **aid**: Rider number (anonomyzed Numeric)\n",
    "* **fAid**: Rider number (anonomyzed Factor)\n",
    "* **date**: Date of the ride (as Date)\n",
    "* **fDate**: Date of the ride (as Factor)\n",
    "* **AfternoonId**: Function of Date, only true for Route 5\n",
    "\n",
    "#### Main outcome / predictor\n",
    "* **did_ride**: Did the rider ride on this date?\n",
    "* **imputed_new_buses**: The weighted average of the fraction of new busses \n",
    "     on the routes the rider took on the last (up to) 10 trips\n",
    "\n",
    "#### Time since last ride\n",
    "* **commutes_since_last_ride**: Number of commutes since rider's last ride (numeric; range 1 - 461)\n",
    "* **f_commutes_since_last_ride**: Number of commutes since rider's last ride (factor; range \"1\" - \"40+\")\n",
    "     \n",
    "#### Date based indicators\n",
    "* **SR520WBHOV**: SR 520 West Bound is open (Function of the date)\n",
    "* **SR520EBHOV**: SR 520 East Bound is open (Function of the date)\n",
    "* **I405HOV**: Is a 405 HOV is open (Function of the date )\n",
    "* **Route5Expansion**: Route 5 expanded (Function of Date )\n",
    "\n",
    "#### Features based on the rider's history\n",
    "* **route_X_10_ride** (e.g. `route_3_10_ride`):  Fraction of the rider's last 10 rides that were taken on route X\n",
    "* **is_peak_10_ride**: Fraction of the rider's last 10 rides that were taken **during peak traffic**\n",
    "* **IsESOther_10_ride**: Fraction of the rider's last 10 rides that were taken on **EastSide (other) routes**\n",
    "* **IsRouteSeattle_10_ride**: Fraction of the rider's last 10 rides that were taken on **Seattle Routes**\n",
    "* **Is405North_10_ride**: Fraction of the rider's last 10 rides that were taken on **I 405 North Routes**\n",
    "* **IsCoach_10_ride**: Fraction of the rider's last 10 rides that were taken on  **Coach (as opposed to shuttle) busses**\n",
    "* **first_stop_10_ride**: Fraction of the rider's last 10 rides that were taken from **the last AM stop**\n",
    "* **last_stop_10_ride**: Fraction of the rider's last 10 rides that were taken on  **the first AM stop**\n",
    "* **single_stop_10_ride**: Fraction of the rider's last 10 rides that were taken on **a Single Stop Route**\n",
    "* **vehicle_is_new_10_ride**: Fraction of the rider's last 10 rides that were taken on **a new vehicle**"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## A Handy Utility function for fitting models and gathering summary statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "#' A cute little function for fitting a model and pulling out the headline statistics\n",
    "#'\n",
    "#' @param data A dataset for fitting the model\n",
    "#' @param model A number for identifying the model in a table (these second field in the \"coef\" output)\n",
    "#' @param lhs The left hand side of the model (as a string)\n",
    "#' @param predictors The effects of interested.  Specifically these are the effects that will be pulled out in the summary table\n",
    "#' @param adjust_for The fixed effects that will be included in the right hand side but not pulled out into the summar table\n",
    "#'\n",
    "#' @return A list containing the glm model (`$model`), and a matrix of interesting statistics from the\n",
    "#'       various models (`$coef`)\n",
    "\n",
    "fit_ridership_logit_models <- function(data,\n",
    "                                        model=1,\n",
    "                                        lhs=\"did_ride\",\n",
    "                                        predictors=\"new_fraction_10day\",\n",
    "                                        adjust_for=c(\"fDate\",route_field),# up to 231 levels\n",
    "                                        quick=FALSE,\n",
    "                                        boot.reps=1001,\n",
    "                                        granularity=\"\"){\n",
    "\n",
    "    # build and test the formula \n",
    "    (FMLA <- formula(paste(lhs,'~',paste(c(predictors,adjust_for),collapse=' + '))))\n",
    "    .updated = as.character(update(FMLA,~.))\n",
    "    if(length(.updated)>1){\n",
    "        .rhs = .updated[3]\n",
    "    }else{\n",
    "        .rhs = strsplit(as.character(update(FMLA,~.)),\" *~ *\")[[1]][2]\n",
    "    }\n",
    "    .terms = strsplit(.rhs,\" *\\\\+ *\")[[1]]\n",
    "    \n",
    "    \n",
    "    .vars = get.vars(rhs(FMLA))\n",
    "    if(any(! (.vars %in% names(data))))\n",
    "           stop(paste(\"missing variable: \",.vars[! (.vars %in% names(data))],collapse=\"\\\\n\"))\n",
    "           \n",
    "    if(any(!(predictors %in% .terms))){\n",
    "        cat(\"\\n===============================================\\n\")\n",
    "        cat(\"terms :\\n\")\n",
    "        cat(paste0(.terms,\"\\n\"))\n",
    "        cat(\"\\npredictors :\\n\")\n",
    "        cat(paste0(predictors[!(predictors %in% .terms)],\"\\n\"))\n",
    "        cat(\"\\n===============================================\\n\")\n",
    "        stop(\"Bad Predctors\")\n",
    "        \n",
    "    }    \n",
    "    \n",
    "    quick_N <- 5e5\n",
    "    if(quick & data[,.N] > quick_N)\n",
    "        data <- data[sample(.N,quick_N)]\n",
    "    \n",
    "    # FIT THE OLS MODELS\n",
    "    if(TRUE){\n",
    "        \n",
    "        (FMLA <- formula(paste(lhs,'~',paste(c(predictors,adjust_for),collapse=' + '))))\n",
    "        LM <- glm(FMLA, data = data) # required for the wild bootstrap\n",
    "    }else{\n",
    "        (FMLA_main <- formula(paste(lhs,'~',paste(c(predictors),collapse=' + '))))\n",
    "        (FMLA_fixed <- formula(paste('~',paste(adjust_for,collapse=' + '))))\n",
    "\n",
    "        # doesn't work (LM <- lm_robust(FMLA_main,  data = data, fixed = FMLA_fixed) )\n",
    "        (LM <- do.call(lm_robust,list(FMLA_main, data = data, fixed = FMLA_fixed,se_type=\"classical\") )) # I hate magic\n",
    "    }\n",
    "    \n",
    "    # SUMMARY OF THE OLS MODEL\n",
    "    cat(\"\\n===============================================\\n\")\n",
    "    cat(\"Model \",model,\":\")\n",
    "    cat(\"\\n===============================================\\n\")\n",
    "   \n",
    "    cat(\"\\n\\nCoefficients from Linear model (adjust_for effects omitted):\\n\")\n",
    "    \n",
    "    # catch the re-ordering of interaction terms introduced by the update(form,dev.new ~ .) call in cluster.wild.glm\n",
    "    tryCatch({\n",
    "        print(coef(summary(LM))[predictors,])    \n",
    "    },error = function(err){\n",
    "        model_coef = dimnames(coef(summary(LM)))[[1]]\n",
    "        cat(\"\\n=------------------------======================\\n\")\n",
    "            print(FMLA)\n",
    "            print(coef(summary(LM)))\n",
    "        cat(\"\\n=------------------------======================\\n\")\n",
    "        cat(\"Missing coefficients:\\n\",\n",
    "            predictors[! predictors %in% model_coef])\n",
    "        cat(\"\\n\\nAvailable coefficients:\\n\")\n",
    "        \n",
    "        print(model_coef)\n",
    "        stop(err)\n",
    "    })\n",
    "\n",
    "    # DO THE WILD BOOTSTRAP\n",
    "    # set.seed(10101)\n",
    "    # cl <-cluster.wild.glm(LM, dat = data, cluster = ~ factor(favorite_route), boot.reps = boot.reps, report=FALSE )\n",
    "\n",
    "    # MAKE THE PRETTY OUTPUT\n",
    "    # without doing the (slow) wild bootstrap\n",
    "    out <- cbind(model=model,\n",
    "                rbind(coef(summary(LM))[predictors,]),\n",
    "                # rbind(cl$ci[predictors,]),\n",
    "                N=data[,.N],\n",
    "                granularity=granularity)\n",
    "\n",
    "    rm(LM); gc() # alas...\n",
    "    # dimnames(out)[[1]] <- predictors\n",
    "    return(out)\n",
    "\n",
    "} "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Fit the Models for table 2\n",
    "* Pre 520 HOV data only"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  1 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "     Estimate    Std. Error       t value      Pr(>|t|) \n",
      " 5.283396e-02  1.482465e-03  3.563925e+01 6.209419e-278 \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>1                           </td><td>0.0528339581963518          </td><td>0.00148246544620767         </td><td>35.6392510405606            </td><td>6.20941872847147e-278       </td><td>689102                      </td><td>rider/date/commute [Pre-HOV]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{lllllll}\n",
       " model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & N & granularity\\\\\n",
       "\\hline\n",
       "\t 1                                & 0.0528339581963518               & 0.00148246544620767              & 35.6392510405606                 & 6.20941872847147e-278            & 689102                           & rider/date/commute {[}Pre-HOV{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| model | Estimate | Std. Error | t value | Pr(>|t|) | N | granularity |\n",
       "|---|---|---|---|---|---|---|\n",
       "| 1                            | 0.0528339581963518           | 0.00148246544620767          | 35.6392510405606             | 6.20941872847147e-278        | 689102                       | rider/date/commute [Pre-HOV] |\n",
       "\n"
      ],
      "text/plain": [
       "     model Estimate           Std. Error          t value         \n",
       "[1,] 1     0.0528339581963518 0.00148246544620767 35.6392510405606\n",
       "     Pr(>|t|)              N      granularity                 \n",
       "[1,] 6.20941872847147e-278 689102 rider/date/commute [Pre-HOV]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(table2_model1_pre_HOV = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) &  (!SR520EBHOV)],\n",
    "                            predictors=c(\"imputed_new_buses\"),\n",
    "                            adjust_for=c(\"f_favorite_route\", \"f_commutes_since_last_ride\"),\n",
    "                            model=1,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  2 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                           Estimate  Std. Error   t value\n",
      "imputed_new_buses                        0.04759794 0.001988465 23.937020\n",
      "imputed_new_buses:IsRouteSeattle_10_ride 0.01143608 0.002894543  3.950912\n",
      "                                              Pr(>|t|)\n",
      "imputed_new_buses                        1.421581e-126\n",
      "imputed_new_buses:IsRouteSeattle_10_ride  7.786170e-05\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>2                           </td><td>0.0475979374161756          </td><td>0.00198846545600364         </td><td>23.9370200133306            </td><td>1.42158113901658e-126       </td><td>689102                      </td><td>rider/date/commute [Pre-HOV]</td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>2                           </td><td>0.0114360839457607          </td><td>0.00289454283523959         </td><td>3.95091197357045            </td><td>7.78617043656121e-05        </td><td>689102                      </td><td>rider/date/commute [Pre-HOV]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 2                                & 0.0475979374161756               & 0.00198846545600364              & 23.9370200133306                 & 1.42158113901658e-126            & 689102                           & rider/date/commute {[}Pre-HOV{]}\\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 2                                & 0.0114360839457607               & 0.00289454283523959              & 3.95091197357045                 & 7.78617043656121e-05             & 689102                           & rider/date/commute {[}Pre-HOV{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 2                            | 0.0475979374161756           | 0.00198846545600364          | 23.9370200133306             | 1.42158113901658e-126        | 689102                       | rider/date/commute [Pre-HOV] |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 2                            | 0.0114360839457607           | 0.00289454283523959          | 3.95091197357045             | 7.78617043656121e-05         | 689102                       | rider/date/commute [Pre-HOV] |\n",
       "\n"
      ],
      "text/plain": [
       "                                         model Estimate          \n",
       "imputed_new_buses                        2     0.0475979374161756\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 2     0.0114360839457607\n",
       "                                         Std. Error          t value         \n",
       "imputed_new_buses                        0.00198846545600364 23.9370200133306\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.00289454283523959 3.95091197357045\n",
       "                                         Pr(>|t|)              N     \n",
       "imputed_new_buses                        1.42158113901658e-126 689102\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 7.78617043656121e-05  689102\n",
       "                                         granularity                 \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV]\n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(table2_model2 = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & \n",
    "                                                            (!SR520EBHOV)],\n",
    "                            predictors=c(\"imputed_new_buses\",\n",
    "                                            \"imputed_new_buses:IsRouteSeattle_10_ride\"),\n",
    "                            adjust_for=c(\"f_favorite_route\",\n",
    "                                            \"f_commutes_since_last_ride\"),\n",
    "                            model=2,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  3 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                           Estimate  Std. Error   t value\n",
      "imputed_new_buses                        0.04479687 0.002618136 17.110216\n",
      "imputed_new_buses:IsRouteSeattle_10_ride 0.01912009 0.004086646  4.678677\n",
      "                                             Pr(>|t|)\n",
      "imputed_new_buses                        1.335894e-65\n",
      "imputed_new_buses:IsRouteSeattle_10_ride 2.888550e-06\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>3                                                        </td><td>0.0447968656862659                                       </td><td>0.00261813564889926                                      </td><td>17.1102157006646                                         </td><td>1.33589424029762e-65                                     </td><td>307332                                                   </td><td>rider/date/commute [Pre-HOV; First stop preferred riders]</td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>3                                                        </td><td>0.0191200932650699                                       </td><td>0.00408664553452908                                      </td><td>4.67867670526341                                         </td><td>2.88854977705162e-06                                     </td><td>307332                                                   </td><td>rider/date/commute [Pre-HOV; First stop preferred riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 3                                                             & 0.0447968656862659                                            & 0.00261813564889926                                           & 17.1102157006646                                              & 1.33589424029762e-65                                          & 307332                                                        & rider/date/commute {[}Pre-HOV; First stop preferred riders{]}\\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 3                                                             & 0.0191200932650699                                            & 0.00408664553452908                                           & 4.67867670526341                                              & 2.88854977705162e-06                                          & 307332                                                        & rider/date/commute {[}Pre-HOV; First stop preferred riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 3                                                         | 0.0447968656862659                                        | 0.00261813564889926                                       | 17.1102157006646                                          | 1.33589424029762e-65                                      | 307332                                                    | rider/date/commute [Pre-HOV; First stop preferred riders] |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 3                                                         | 0.0191200932650699                                        | 0.00408664553452908                                       | 4.67867670526341                                          | 2.88854977705162e-06                                      | 307332                                                    | rider/date/commute [Pre-HOV; First stop preferred riders] |\n",
       "\n"
      ],
      "text/plain": [
       "                                         model Estimate          \n",
       "imputed_new_buses                        3     0.0447968656862659\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 3     0.0191200932650699\n",
       "                                         Std. Error          t value         \n",
       "imputed_new_buses                        0.00261813564889926 17.1102157006646\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.00408664553452908 4.67867670526341\n",
       "                                         Pr(>|t|)             N     \n",
       "imputed_new_buses                        1.33589424029762e-65 307332\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 2.88854977705162e-06 307332\n",
       "                                         granularity                                              \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV; First stop preferred riders]\n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV; First stop preferred riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(table2_model3_pre_HOV = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) &  \n",
    "                                                            (!SR520EBHOV) & \n",
    "                                                            (first_stop_10_ride >= 0.5)],\n",
    "                            predictors=c(\"imputed_new_buses\",\n",
    "                                            \"imputed_new_buses:IsRouteSeattle_10_ride\"),\n",
    "                            adjust_for=c(\"f_favorite_route\",\n",
    "                                            \"f_commutes_since_last_ride\"),\n",
    "                            model=3,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV; First stop preferred riders]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  4 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                           Estimate  Std. Error   t value\n",
      "imputed_new_buses                        0.04969017 0.002234043 22.242261\n",
      "imputed_new_buses:IsRouteSeattle_10_ride 0.01014472 0.003464251  2.928403\n",
      "                                              Pr(>|t|)\n",
      "imputed_new_buses                        1.527235e-109\n",
      "imputed_new_buses:IsRouteSeattle_10_ride  3.407250e-03\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>4                                                       </td><td>0.0496901746886832                                      </td><td>0.00223404330471197                                     </td><td>22.2422611879896                                        </td><td>1.52723466400494e-109                                   </td><td>470230                                                  </td><td>rider/date/commute [Pre-HOV; Last stop preferred riders]</td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>4                                                       </td><td>0.0101447208082524                                      </td><td>0.00346425082947353                                     </td><td>2.92840250536771                                        </td><td>0.00340725005985901                                     </td><td>470230                                                  </td><td>rider/date/commute [Pre-HOV; Last stop preferred riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 4                                                            & 0.0496901746886832                                           & 0.00223404330471197                                          & 22.2422611879896                                             & 1.52723466400494e-109                                        & 470230                                                       & rider/date/commute {[}Pre-HOV; Last stop preferred riders{]}\\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 4                                                            & 0.0101447208082524                                           & 0.00346425082947353                                          & 2.92840250536771                                             & 0.00340725005985901                                          & 470230                                                       & rider/date/commute {[}Pre-HOV; Last stop preferred riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 4                                                        | 0.0496901746886832                                       | 0.00223404330471197                                      | 22.2422611879896                                         | 1.52723466400494e-109                                    | 470230                                                   | rider/date/commute [Pre-HOV; Last stop preferred riders] |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 4                                                        | 0.0101447208082524                                       | 0.00346425082947353                                      | 2.92840250536771                                         | 0.00340725005985901                                      | 470230                                                   | rider/date/commute [Pre-HOV; Last stop preferred riders] |\n",
       "\n"
      ],
      "text/plain": [
       "                                         model Estimate          \n",
       "imputed_new_buses                        4     0.0496901746886832\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 4     0.0101447208082524\n",
       "                                         Std. Error          t value         \n",
       "imputed_new_buses                        0.00223404330471197 22.2422611879896\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.00346425082947353 2.92840250536771\n",
       "                                         Pr(>|t|)              N     \n",
       "imputed_new_buses                        1.52723466400494e-109 470230\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.00340725005985901   470230\n",
       "                                         granularity                                             \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV; Last stop preferred riders]\n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV; Last stop preferred riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(table2_model4_pre_HOV = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & \n",
    "                                                            (!SR520EBHOV) & \n",
    "                                                            (last_stop_10_ride >= 0.5)],\n",
    "                            predictors=c(\"imputed_new_buses\",\n",
    "                                            \"imputed_new_buses:IsRouteSeattle_10_ride\"),\n",
    "                            adjust_for=c(\"f_favorite_route\",\n",
    "                                            \"f_commutes_since_last_ride\"),\n",
    "                            model=4,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV; Last stop preferred riders]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  5 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "     Estimate    Std. Error       t value      Pr(>|t|) \n",
      " 5.998727e-02  2.278536e-03  2.632711e+01 1.272104e-152 \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>5                                                     </td><td>0.0599872730426233                                    </td><td>0.00227853582546204                                   </td><td>26.3271142688569                                      </td><td>1.27210424947312e-152                                 </td><td>395760                                                </td><td>rider/date/commute [Pre-HOV; Seattle preferred riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{lllllll}\n",
       " model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & N & granularity\\\\\n",
       "\\hline\n",
       "\t 5                                                          & 0.0599872730426233                                         & 0.00227853582546204                                        & 26.3271142688569                                           & 1.27210424947312e-152                                      & 395760                                                     & rider/date/commute {[}Pre-HOV; Seattle preferred riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| model | Estimate | Std. Error | t value | Pr(>|t|) | N | granularity |\n",
       "|---|---|---|---|---|---|---|\n",
       "| 5                                                      | 0.0599872730426233                                     | 0.00227853582546204                                    | 26.3271142688569                                       | 1.27210424947312e-152                                  | 395760                                                 | rider/date/commute [Pre-HOV; Seattle preferred riders] |\n",
       "\n"
      ],
      "text/plain": [
       "     model Estimate           Std. Error          t value         \n",
       "[1,] 5     0.0599872730426233 0.00227853582546204 26.3271142688569\n",
       "     Pr(>|t|)              N     \n",
       "[1,] 1.27210424947312e-152 395760\n",
       "     granularity                                           \n",
       "[1,] rider/date/commute [Pre-HOV; Seattle preferred riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(table2_model5_pre_HOV = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & \n",
    "                                                            (!SR520EBHOV) & \n",
    "                                                            IsRouteSeattle_10_ride >= 0.5],\n",
    "                            predictors=c(\"imputed_new_buses\"),\n",
    "                            adjust_for=c(\"f_favorite_route\",\n",
    "                                            \"f_commutes_since_last_ride\"),\n",
    "                            model=5,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV; Seattle preferred riders]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  6 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "     Estimate    Std. Error       t value      Pr(>|t|) \n",
      " 4.604260e-02  1.885627e-03  2.441766e+01 1.502301e-131 \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>6                                                         </td><td>0.0460426019746353                                        </td><td>0.00188562684146185                                       </td><td>24.4176636449131                                          </td><td>1.50230058614445e-131                                     </td><td>294658                                                    </td><td>rider/date/commute [Pre-HOV; Non-Seattle preferred riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{lllllll}\n",
       " model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & N & granularity\\\\\n",
       "\\hline\n",
       "\t 6                                                              & 0.0460426019746353                                             & 0.00188562684146185                                            & 24.4176636449131                                               & 1.50230058614445e-131                                          & 294658                                                         & rider/date/commute {[}Pre-HOV; Non-Seattle preferred riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| model | Estimate | Std. Error | t value | Pr(>|t|) | N | granularity |\n",
       "|---|---|---|---|---|---|---|\n",
       "| 6                                                          | 0.0460426019746353                                         | 0.00188562684146185                                        | 24.4176636449131                                           | 1.50230058614445e-131                                      | 294658                                                     | rider/date/commute [Pre-HOV; Non-Seattle preferred riders] |\n",
       "\n"
      ],
      "text/plain": [
       "     model Estimate           Std. Error          t value         \n",
       "[1,] 6     0.0460426019746353 0.00188562684146185 24.4176636449131\n",
       "     Pr(>|t|)              N     \n",
       "[1,] 1.50230058614445e-131 294658\n",
       "     granularity                                               \n",
       "[1,] rider/date/commute [Pre-HOV; Non-Seattle preferred riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(table2_model6_pre_HOV = fit_ridership_logit_models(data = commute_ride_data[(!SR520WBHOV) & \n",
    "                                                            (!SR520EBHOV) & \n",
    "                                                            IsRouteSeattle_10_ride <= 0.5],\n",
    "                            predictors=c(\"imputed_new_buses\"),\n",
    "                            adjust_for=c(\"f_favorite_route\",\n",
    "                                            \"f_commutes_since_last_ride\"),\n",
    "                            model=6,\n",
    "                            granularity=\"rider/date/commute [Pre-HOV; Non-Seattle preferred riders]\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Table 2 Summary Statistics \n",
    "* Pre 520 HOV data only"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row></th><td>1                                                         </td><td>0.0528339581963518                                        </td><td>0.00148246544620767                                       </td><td>35.6392510405606                                          </td><td>6.20941872847147e-278                                     </td><td>689102                                                    </td><td>rider/date/commute [Pre-HOV]                              </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>2                                                         </td><td>0.0475979374161756                                        </td><td>0.00198846545600364                                       </td><td>23.9370200133306                                          </td><td>1.42158113901658e-126                                     </td><td>689102                                                    </td><td>rider/date/commute [Pre-HOV]                              </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>2                                                         </td><td>0.0114360839457607                                        </td><td>0.00289454283523959                                       </td><td>3.95091197357045                                          </td><td>7.78617043656121e-05                                      </td><td>689102                                                    </td><td>rider/date/commute [Pre-HOV]                              </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>3                                                         </td><td>0.0447968656862659                                        </td><td>0.00261813564889926                                       </td><td>17.1102157006646                                          </td><td>1.33589424029762e-65                                      </td><td>307332                                                    </td><td>rider/date/commute [Pre-HOV; First stop preferred riders] </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>3                                                         </td><td>0.0191200932650699                                        </td><td>0.00408664553452908                                       </td><td>4.67867670526341                                          </td><td>2.88854977705162e-06                                      </td><td>307332                                                    </td><td>rider/date/commute [Pre-HOV; First stop preferred riders] </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>4                                                         </td><td>0.0496901746886832                                        </td><td>0.00223404330471197                                       </td><td>22.2422611879896                                          </td><td>1.52723466400494e-109                                     </td><td>470230                                                    </td><td>rider/date/commute [Pre-HOV; Last stop preferred riders]  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:IsRouteSeattle_10_ride</th><td>4                                                         </td><td>0.0101447208082524                                        </td><td>0.00346425082947353                                       </td><td>2.92840250536771                                          </td><td>0.00340725005985901                                       </td><td>470230                                                    </td><td>rider/date/commute [Pre-HOV; Last stop preferred riders]  </td></tr>\n",
       "\t<tr><th scope=row></th><td>5                                                         </td><td>0.0599872730426233                                        </td><td>0.00227853582546204                                       </td><td>26.3271142688569                                          </td><td>1.27210424947312e-152                                     </td><td>395760                                                    </td><td>rider/date/commute [Pre-HOV; Seattle preferred riders]    </td></tr>\n",
       "\t<tr><th scope=row></th><td>6                                                         </td><td>0.0460426019746353                                        </td><td>0.00188562684146185                                       </td><td>24.4176636449131                                          </td><td>1.50230058614445e-131                                     </td><td>294658                                                    </td><td>rider/date/commute [Pre-HOV; Non-Seattle preferred riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & N & granularity\\\\\n",
       "\\hline\n",
       "\t & 1                                                              & 0.0528339581963518                                             & 0.00148246544620767                                            & 35.6392510405606                                               & 6.20941872847147e-278                                          & 689102                                                         & rider/date/commute {[}Pre-HOV{]}                              \\\\\n",
       "\timputed\\_new\\_buses & 2                                                              & 0.0475979374161756                                             & 0.00198846545600364                                            & 23.9370200133306                                               & 1.42158113901658e-126                                          & 689102                                                         & rider/date/commute {[}Pre-HOV{]}                              \\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 2                                                              & 0.0114360839457607                                             & 0.00289454283523959                                            & 3.95091197357045                                               & 7.78617043656121e-05                                           & 689102                                                         & rider/date/commute {[}Pre-HOV{]}                              \\\\\n",
       "\timputed\\_new\\_buses & 3                                                              & 0.0447968656862659                                             & 0.00261813564889926                                            & 17.1102157006646                                               & 1.33589424029762e-65                                           & 307332                                                         & rider/date/commute {[}Pre-HOV; First stop preferred riders{]} \\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 3                                                              & 0.0191200932650699                                             & 0.00408664553452908                                            & 4.67867670526341                                               & 2.88854977705162e-06                                           & 307332                                                         & rider/date/commute {[}Pre-HOV; First stop preferred riders{]} \\\\\n",
       "\timputed\\_new\\_buses & 4                                                              & 0.0496901746886832                                             & 0.00223404330471197                                            & 22.2422611879896                                               & 1.52723466400494e-109                                          & 470230                                                         & rider/date/commute {[}Pre-HOV; Last stop preferred riders{]}  \\\\\n",
       "\timputed\\_new\\_buses:IsRouteSeattle\\_10\\_ride & 4                                                              & 0.0101447208082524                                             & 0.00346425082947353                                            & 2.92840250536771                                               & 0.00340725005985901                                            & 470230                                                         & rider/date/commute {[}Pre-HOV; Last stop preferred riders{]}  \\\\\n",
       "\t & 5                                                              & 0.0599872730426233                                             & 0.00227853582546204                                            & 26.3271142688569                                               & 1.27210424947312e-152                                          & 395760                                                         & rider/date/commute {[}Pre-HOV; Seattle preferred riders{]}    \\\\\n",
       "\t & 6                                                              & 0.0460426019746353                                             & 0.00188562684146185                                            & 24.4176636449131                                               & 1.50230058614445e-131                                          & 294658                                                         & rider/date/commute {[}Pre-HOV; Non-Seattle preferred riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "|  | 1                                                          | 0.0528339581963518                                         | 0.00148246544620767                                        | 35.6392510405606                                           | 6.20941872847147e-278                                      | 689102                                                     | rider/date/commute [Pre-HOV]                               |\n",
       "| imputed_new_buses | 2                                                          | 0.0475979374161756                                         | 0.00198846545600364                                        | 23.9370200133306                                           | 1.42158113901658e-126                                      | 689102                                                     | rider/date/commute [Pre-HOV]                               |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 2                                                          | 0.0114360839457607                                         | 0.00289454283523959                                        | 3.95091197357045                                           | 7.78617043656121e-05                                       | 689102                                                     | rider/date/commute [Pre-HOV]                               |\n",
       "| imputed_new_buses | 3                                                          | 0.0447968656862659                                         | 0.00261813564889926                                        | 17.1102157006646                                           | 1.33589424029762e-65                                       | 307332                                                     | rider/date/commute [Pre-HOV; First stop preferred riders]  |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 3                                                          | 0.0191200932650699                                         | 0.00408664553452908                                        | 4.67867670526341                                           | 2.88854977705162e-06                                       | 307332                                                     | rider/date/commute [Pre-HOV; First stop preferred riders]  |\n",
       "| imputed_new_buses | 4                                                          | 0.0496901746886832                                         | 0.00223404330471197                                        | 22.2422611879896                                           | 1.52723466400494e-109                                      | 470230                                                     | rider/date/commute [Pre-HOV; Last stop preferred riders]   |\n",
       "| imputed_new_buses:IsRouteSeattle_10_ride | 4                                                          | 0.0101447208082524                                         | 0.00346425082947353                                        | 2.92840250536771                                           | 0.00340725005985901                                        | 470230                                                     | rider/date/commute [Pre-HOV; Last stop preferred riders]   |\n",
       "|  | 5                                                          | 0.0599872730426233                                         | 0.00227853582546204                                        | 26.3271142688569                                           | 1.27210424947312e-152                                      | 395760                                                     | rider/date/commute [Pre-HOV; Seattle preferred riders]     |\n",
       "|  | 6                                                          | 0.0460426019746353                                         | 0.00188562684146185                                        | 24.4176636449131                                           | 1.50230058614445e-131                                      | 294658                                                     | rider/date/commute [Pre-HOV; Non-Seattle preferred riders] |\n",
       "\n"
      ],
      "text/plain": [
       "                                         model Estimate          \n",
       "                                         1     0.0528339581963518\n",
       "imputed_new_buses                        2     0.0475979374161756\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 2     0.0114360839457607\n",
       "imputed_new_buses                        3     0.0447968656862659\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 3     0.0191200932650699\n",
       "imputed_new_buses                        4     0.0496901746886832\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 4     0.0101447208082524\n",
       "                                         5     0.0599872730426233\n",
       "                                         6     0.0460426019746353\n",
       "                                         Std. Error          t value         \n",
       "                                         0.00148246544620767 35.6392510405606\n",
       "imputed_new_buses                        0.00198846545600364 23.9370200133306\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.00289454283523959 3.95091197357045\n",
       "imputed_new_buses                        0.00261813564889926 17.1102157006646\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.00408664553452908 4.67867670526341\n",
       "imputed_new_buses                        0.00223404330471197 22.2422611879896\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.00346425082947353 2.92840250536771\n",
       "                                         0.00227853582546204 26.3271142688569\n",
       "                                         0.00188562684146185 24.4176636449131\n",
       "                                         Pr(>|t|)              N     \n",
       "                                         6.20941872847147e-278 689102\n",
       "imputed_new_buses                        1.42158113901658e-126 689102\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 7.78617043656121e-05  689102\n",
       "imputed_new_buses                        1.33589424029762e-65  307332\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 2.88854977705162e-06  307332\n",
       "imputed_new_buses                        1.52723466400494e-109 470230\n",
       "imputed_new_buses:IsRouteSeattle_10_ride 0.00340725005985901   470230\n",
       "                                         1.27210424947312e-152 395760\n",
       "                                         1.50230058614445e-131 294658\n",
       "                                         granularity                                               \n",
       "                                         rider/date/commute [Pre-HOV]                              \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV]                              \n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV]                              \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV; First stop preferred riders] \n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV; First stop preferred riders] \n",
       "imputed_new_buses                        rider/date/commute [Pre-HOV; Last stop preferred riders]  \n",
       "imputed_new_buses:IsRouteSeattle_10_ride rider/date/commute [Pre-HOV; Last stop preferred riders]  \n",
       "                                         rider/date/commute [Pre-HOV; Seattle preferred riders]    \n",
       "                                         rider/date/commute [Pre-HOV; Non-Seattle preferred riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "rbind( table2_model1_pre_HOV,\n",
    "       table2_model2,\n",
    "       table2_model3_pre_HOV,\n",
    "       table2_model4_pre_HOV,\n",
    "       table2_model5_pre_HOV,\n",
    "       table2_model6_pre_HOV)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Fit the Models for Table 3 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "2"
      ],
      "text/latex": [
       "2"
      ],
      "text/markdown": [
       "2"
      ],
      "text/plain": [
       "[1] 2"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>used</th><th scope=col>(Mb)</th><th scope=col>gc trigger</th><th scope=col>(Mb)</th><th scope=col>max used</th><th scope=col>(Mb)</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>Ncells</th><td>  2015694</td><td>107.7    </td><td>  5656417</td><td> 302.1   </td><td> 11047692</td><td> 590.1   </td></tr>\n",
       "\t<tr><th scope=row>Vcells</th><td>127409895</td><td>972.1    </td><td>403334517</td><td>3077.2   </td><td>471095900</td><td>3594.2   </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|llllll}\n",
       "  & used & (Mb) & gc trigger & (Mb) & max used & (Mb)\\\\\n",
       "\\hline\n",
       "\tNcells &   2015694 & 107.7     &   5656417 &  302.1    &  11047692 &  590.1   \\\\\n",
       "\tVcells & 127409895 & 972.1     & 403334517 & 3077.2    & 471095900 & 3594.2   \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | used | (Mb) | gc trigger | (Mb) | max used | (Mb) |\n",
       "|---|---|---|---|---|---|---|\n",
       "| Ncells |   2015694 | 107.7     |   5656417 |  302.1    |  11047692 |  590.1    |\n",
       "| Vcells | 127409895 | 972.1     | 403334517 | 3077.2    | 471095900 | 3594.2    |\n",
       "\n"
      ],
      "text/plain": [
       "       used      (Mb)  gc trigger (Mb)   max used  (Mb)  \n",
       "Ncells   2015694 107.7   5656417   302.1  11047692  590.1\n",
       "Vcells 127409895 972.1 403334517  3077.2 471095900 3594.2"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "1 + 1\n",
    "gc()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  1 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "    Estimate   Std. Error      t value     Pr(>|t|) \n",
      "8.145965e-03 8.165498e-04 9.976078e+00 1.942971e-23 \n"
     ]
    }
   ],
   "source": [
    "\n",
    "table3_model1 = fit_ridership_logit_models(data = commute_ride_data,\n",
    "                        predictors=c(\"post_hov:IsRouteSeattle_10_ride\"),\n",
    "                        adjust_for=c(\"imputed_new_buses + AfternoonId + fDate\",\n",
    "                                        \"f_commutes_since_last_ride\",\n",
    "                                        \"f_favorite_route\"),\n",
    "                        model=1,\n",
    "                        granularity=\"rider/date/commute\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  2 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                                    Estimate  Std. Error\n",
      "post_hov:IsRouteSeattle_10_ride                 0.0079905645 0.001464419\n",
      "is_peak_10_ride                                 0.0002990732 0.001204508\n",
      "IsRouteSeattle_10_ride:is_peak_10_ride          0.0083374249 0.001548644\n",
      "post_hov:is_peak_10_ride                        0.0021394520 0.001621824\n",
      "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 0.0004122397 0.002088035\n",
      "                                                  t value     Pr(>|t|)\n",
      "post_hov:IsRouteSeattle_10_ride                 5.4564748 4.857538e-08\n",
      "is_peak_10_ride                                 0.2482949 8.039063e-01\n",
      "IsRouteSeattle_10_ride:is_peak_10_ride          5.3836944 7.298285e-08\n",
      "post_hov:is_peak_10_ride                        1.3191640 1.871145e-01\n",
      "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 0.1974295 8.434915e-01\n"
     ]
    }
   ],
   "source": [
    "\n",
    "table3_model2 = fit_ridership_logit_models(data = commute_ride_data,\n",
    "                        predictors=c(\"post_hov:IsRouteSeattle_10_ride\",\n",
    "                                        \"is_peak_10_ride\",\n",
    "                                        \"IsRouteSeattle_10_ride:is_peak_10_ride\",\n",
    "                                        \"post_hov:is_peak_10_ride\",\n",
    "                                        \"post_hov:IsRouteSeattle_10_ride:is_peak_10_ride\"\n",
    "                                ),\n",
    "                        model=2,\n",
    "                        adjust_for=c(\"imputed_new_buses + AfternoonId + fDate\",\n",
    "                                        \"f_commutes_since_last_ride\",\n",
    "                                        \"f_favorite_route\"),\n",
    "                        granularity=\"rider/date/commute\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  3 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "    Estimate   Std. Error      t value     Pr(>|t|) \n",
      "1.030477e-02 1.176902e-03 8.755838e+00 2.030367e-18 \n"
     ]
    }
   ],
   "source": [
    "\n",
    "table3_model3 = fit_ridership_logit_models(data = commute_ride_data[first_stop_10_ride >= 0.5],\n",
    "                        predictors=c(\"post_hov:IsRouteSeattle_10_ride\"),\n",
    "                        adjust_for=c(\"imputed_new_buses\",\n",
    "                                        \"fDate\",\n",
    "                                        \"f_commutes_since_last_ride\",\n",
    "                                        \"f_favorite_route\"),\n",
    "                        model=3,\n",
    "                        granularity=\"rider/date/commute [first stop prefered riders]\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  4 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "    Estimate   Std. Error      t value     Pr(>|t|) \n",
      "6.612480e-03 9.843517e-04 6.717599e+00 1.848352e-11 \n"
     ]
    }
   ],
   "source": [
    "\n",
    "table3_model4 = fit_ridership_logit_models(data = commute_ride_data[last_stop_10_ride >= 0.5],\n",
    "                        predictors=c(\"post_hov:IsRouteSeattle_10_ride\"),\n",
    "                        adjust_for=c(\"imputed_new_buses\",\n",
    "                                        \"fDate\",\n",
    "                                        \"f_commutes_since_last_ride\",\n",
    "                                        \"f_favorite_route\"),\n",
    "                        model=4,\n",
    "                        granularity=\"rider/date/commute [last stop prefered riders]\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  5 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "   Estimate  Std. Error     t value    Pr(>|t|) \n",
      "0.003812830 0.001262077 3.021074480 0.002518878 \n"
     ]
    }
   ],
   "source": [
    "\n",
    "table3_model5 = fit_ridership_logit_models(data = commute_ride_data[date >= as.Date(\"2016-03-01\") & \n",
    "                                                        date < as.Date(\"2016-07-01\")],\n",
    "                        predictors=c(\"post_hov:IsRouteSeattle_10_ride\"),\n",
    "                        adjust_for=c(\"imputed_new_buses\",\n",
    "                                        \"fDate\",\n",
    "                                        \"f_commutes_since_last_ride\",\n",
    "                                        \"f_favorite_route\"),\n",
    "                        model=5,\n",
    "                        granularity=\"ride/date/commute\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Table 3 Summary Statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "2"
      ],
      "text/latex": [
       "2"
      ],
      "text/markdown": [
       "2"
      ],
      "text/plain": [
       "[1] 2"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row></th><td>1                                              </td><td>0.00814596453521805                            </td><td>0.000816549797892522                           </td><td>9.97607807416328                               </td><td>1.94297140804549e-23                           </td><td>1562314                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride</th><td>2                                              </td><td>0.00799056452335063                            </td><td>0.00146441885738006                            </td><td>5.45647475316336                               </td><td>4.85753772776829e-08                           </td><td>1562314                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>is_peak_10_ride</th><td>2                                              </td><td>0.000299073224706864                           </td><td>0.00120450797322407                            </td><td>0.248294931503312                              </td><td>0.803906252960762                              </td><td>1562314                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>IsRouteSeattle_10_ride:is_peak_10_ride</th><td>2                                              </td><td>0.00833742485855916                            </td><td>0.00154864379366524                            </td><td>5.38369436061642                               </td><td>7.29828516747874e-08                           </td><td>1562314                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>post_hov:is_peak_10_ride</th><td>2                                              </td><td>0.00213945198117043                            </td><td>0.00162182415199274                            </td><td>1.31916396641503                               </td><td>0.187114495350031                              </td><td>1562314                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row>post_hov:IsRouteSeattle_10_ride:is_peak_10_ride</th><td>2                                              </td><td>0.000412239686243251                           </td><td>0.00208803528301048                            </td><td>0.197429463763128                              </td><td>0.843491500289839                              </td><td>1562314                                        </td><td>rider/date/commute                             </td></tr>\n",
       "\t<tr><th scope=row></th><td>3                                              </td><td>0.0103047660662732                             </td><td>0.00117690229354875                            </td><td>8.75583820573662                               </td><td>2.03036669123479e-18                           </td><td>688058                                         </td><td>rider/date/commute [first stop prefered riders]</td></tr>\n",
       "\t<tr><th scope=row></th><td>4                                              </td><td>0.0066124797453878                             </td><td>0.000984351664709863                           </td><td>6.71759898667599                               </td><td>1.84835209774837e-11                           </td><td>1068360                                        </td><td>rider/date/commute [last stop prefered riders] </td></tr>\n",
       "\t<tr><th scope=row></th><td>5                                              </td><td>0.00381283002379756                            </td><td>0.00126207746595809                            </td><td>3.0210744796898                                </td><td>0.00251887772350728                            </td><td>759650                                         </td><td>ride/date/commute                              </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & N & granularity\\\\\n",
       "\\hline\n",
       "\t & 1                                               & 0.00814596453521805                             & 0.000816549797892522                            & 9.97607807416328                                & 1.94297140804549e-23                            & 1562314                                         & rider/date/commute                             \\\\\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride & 2                                               & 0.00799056452335063                             & 0.00146441885738006                             & 5.45647475316336                                & 4.85753772776829e-08                            & 1562314                                         & rider/date/commute                             \\\\\n",
       "\tis\\_peak\\_10\\_ride & 2                                               & 0.000299073224706864                            & 0.00120450797322407                             & 0.248294931503312                               & 0.803906252960762                               & 1562314                                         & rider/date/commute                             \\\\\n",
       "\tIsRouteSeattle\\_10\\_ride:is\\_peak\\_10\\_ride & 2                                               & 0.00833742485855916                             & 0.00154864379366524                             & 5.38369436061642                                & 7.29828516747874e-08                            & 1562314                                         & rider/date/commute                             \\\\\n",
       "\tpost\\_hov:is\\_peak\\_10\\_ride & 2                                               & 0.00213945198117043                             & 0.00162182415199274                             & 1.31916396641503                                & 0.187114495350031                               & 1562314                                         & rider/date/commute                             \\\\\n",
       "\tpost\\_hov:IsRouteSeattle\\_10\\_ride:is\\_peak\\_10\\_ride & 2                                               & 0.000412239686243251                            & 0.00208803528301048                             & 0.197429463763128                               & 0.843491500289839                               & 1562314                                         & rider/date/commute                             \\\\\n",
       "\t & 3                                                   & 0.0103047660662732                                  & 0.00117690229354875                                 & 8.75583820573662                                    & 2.03036669123479e-18                                & 688058                                              & rider/date/commute {[}first stop prefered riders{]}\\\\\n",
       "\t & 4                                                   & 0.0066124797453878                                  & 0.000984351664709863                                & 6.71759898667599                                    & 1.84835209774837e-11                                & 1068360                                             & rider/date/commute {[}last stop prefered riders{]} \\\\\n",
       "\t & 5                                               & 0.00381283002379756                             & 0.00126207746595809                             & 3.0210744796898                                 & 0.00251887772350728                             & 759650                                          & ride/date/commute                              \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "|  | 1                                               | 0.00814596453521805                             | 0.000816549797892522                            | 9.97607807416328                                | 1.94297140804549e-23                            | 1562314                                         | rider/date/commute                              |\n",
       "| post_hov:IsRouteSeattle_10_ride | 2                                               | 0.00799056452335063                             | 0.00146441885738006                             | 5.45647475316336                                | 4.85753772776829e-08                            | 1562314                                         | rider/date/commute                              |\n",
       "| is_peak_10_ride | 2                                               | 0.000299073224706864                            | 0.00120450797322407                             | 0.248294931503312                               | 0.803906252960762                               | 1562314                                         | rider/date/commute                              |\n",
       "| IsRouteSeattle_10_ride:is_peak_10_ride | 2                                               | 0.00833742485855916                             | 0.00154864379366524                             | 5.38369436061642                                | 7.29828516747874e-08                            | 1562314                                         | rider/date/commute                              |\n",
       "| post_hov:is_peak_10_ride | 2                                               | 0.00213945198117043                             | 0.00162182415199274                             | 1.31916396641503                                | 0.187114495350031                               | 1562314                                         | rider/date/commute                              |\n",
       "| post_hov:IsRouteSeattle_10_ride:is_peak_10_ride | 2                                               | 0.000412239686243251                            | 0.00208803528301048                             | 0.197429463763128                               | 0.843491500289839                               | 1562314                                         | rider/date/commute                              |\n",
       "|  | 3                                               | 0.0103047660662732                              | 0.00117690229354875                             | 8.75583820573662                                | 2.03036669123479e-18                            | 688058                                          | rider/date/commute [first stop prefered riders] |\n",
       "|  | 4                                               | 0.0066124797453878                              | 0.000984351664709863                            | 6.71759898667599                                | 1.84835209774837e-11                            | 1068360                                         | rider/date/commute [last stop prefered riders]  |\n",
       "|  | 5                                               | 0.00381283002379756                             | 0.00126207746595809                             | 3.0210744796898                                 | 0.00251887772350728                             | 759650                                          | ride/date/commute                               |\n",
       "\n"
      ],
      "text/plain": [
       "                                                model Estimate            \n",
       "                                                1     0.00814596453521805 \n",
       "post_hov:IsRouteSeattle_10_ride                 2     0.00799056452335063 \n",
       "is_peak_10_ride                                 2     0.000299073224706864\n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          2     0.00833742485855916 \n",
       "post_hov:is_peak_10_ride                        2     0.00213945198117043 \n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 2     0.000412239686243251\n",
       "                                                3     0.0103047660662732  \n",
       "                                                4     0.0066124797453878  \n",
       "                                                5     0.00381283002379756 \n",
       "                                                Std. Error          \n",
       "                                                0.000816549797892522\n",
       "post_hov:IsRouteSeattle_10_ride                 0.00146441885738006 \n",
       "is_peak_10_ride                                 0.00120450797322407 \n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          0.00154864379366524 \n",
       "post_hov:is_peak_10_ride                        0.00162182415199274 \n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 0.00208803528301048 \n",
       "                                                0.00117690229354875 \n",
       "                                                0.000984351664709863\n",
       "                                                0.00126207746595809 \n",
       "                                                t value          \n",
       "                                                9.97607807416328 \n",
       "post_hov:IsRouteSeattle_10_ride                 5.45647475316336 \n",
       "is_peak_10_ride                                 0.248294931503312\n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          5.38369436061642 \n",
       "post_hov:is_peak_10_ride                        1.31916396641503 \n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 0.197429463763128\n",
       "                                                8.75583820573662 \n",
       "                                                6.71759898667599 \n",
       "                                                3.0210744796898  \n",
       "                                                Pr(>|t|)             N      \n",
       "                                                1.94297140804549e-23 1562314\n",
       "post_hov:IsRouteSeattle_10_ride                 4.85753772776829e-08 1562314\n",
       "is_peak_10_ride                                 0.803906252960762    1562314\n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          7.29828516747874e-08 1562314\n",
       "post_hov:is_peak_10_ride                        0.187114495350031    1562314\n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride 0.843491500289839    1562314\n",
       "                                                2.03036669123479e-18 688058 \n",
       "                                                1.84835209774837e-11 1068360\n",
       "                                                0.00251887772350728  759650 \n",
       "                                                granularity                                    \n",
       "                                                rider/date/commute                             \n",
       "post_hov:IsRouteSeattle_10_ride                 rider/date/commute                             \n",
       "is_peak_10_ride                                 rider/date/commute                             \n",
       "IsRouteSeattle_10_ride:is_peak_10_ride          rider/date/commute                             \n",
       "post_hov:is_peak_10_ride                        rider/date/commute                             \n",
       "post_hov:IsRouteSeattle_10_ride:is_peak_10_ride rider/date/commute                             \n",
       "                                                rider/date/commute [first stop prefered riders]\n",
       "                                                rider/date/commute [last stop prefered riders] \n",
       "                                                ride/date/commute                              "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "1 + 1\n",
    "rbind( table3_model1,\n",
    "       table3_model2,\n",
    "       table3_model3,\n",
    "       table3_model4,\n",
    "       table3_model5)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Fit the Models for Table 4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  1 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "   Estimate  Std. Error     t value    Pr(>|t|) \n",
      "0.006820459 0.003021673 2.257179580 0.023997963 \n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><td>1                                                </td><td>0.00682045906585944                              </td><td>0.00302167320935502                              </td><td>2.25717958008943                                 </td><td>0.0239979625757054                               </td><td>194386                                           </td><td>rider/date/commute [Single Stop Preferred Riders]</td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{lllllll}\n",
       " model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & N & granularity\\\\\n",
       "\\hline\n",
       "\t 1                                                     & 0.00682045906585944                                   & 0.00302167320935502                                   & 2.25717958008943                                      & 0.0239979625757054                                    & 194386                                                & rider/date/commute {[}Single Stop Preferred Riders{]}\\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| model | Estimate | Std. Error | t value | Pr(>|t|) | N | granularity |\n",
       "|---|---|---|---|---|---|---|\n",
       "| 1                                                 | 0.00682045906585944                               | 0.00302167320935502                               | 2.25717958008943                                  | 0.0239979625757054                                | 194386                                            | rider/date/commute [Single Stop Preferred Riders] |\n",
       "\n"
      ],
      "text/plain": [
       "     model Estimate            Std. Error          t value         \n",
       "[1,] 1     0.00682045906585944 0.00302167320935502 2.25717958008943\n",
       "     Pr(>|t|)           N     \n",
       "[1,] 0.0239979625757054 194386\n",
       "     granularity                                      \n",
       "[1,] rider/date/commute [Single Stop Preferred Riders]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(T4_M1 = fit_ridership_logit_models(data = commute_ride_data[(single_stop_10_ride >= 0.5)],\n",
    "                            predictors=c(\"imputed_new_buses\"),\n",
    "                            adjust_for=c(\"fDate\",\n",
    "                                            \"f_commutes_since_last_ride\",\n",
    "                                           \"f_favorite_route\" ),\n",
    "                            model=1,\n",
    "                            granularity=\"rider/date/commute [Single Stop Preferred Riders]\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  2 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                          Estimate  Std. Error   t value\n",
      "imputed_new_buses                     -0.003211164 0.001434084 -2.239174\n",
      "imputed_new_buses:single_stop_10_ride  0.003760258 0.001426074  2.636790\n",
      "                                         Pr(>|t|)\n",
      "imputed_new_buses                     0.025144726\n",
      "imputed_new_buses:single_stop_10_ride 0.008369546\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>2                   </td><td>-0.00321116368682407</td><td>0.00143408392286025 </td><td>-2.23917417637558   </td><td>0.0251447255715103  </td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>2                   </td><td>0.00376025829653205 </td><td>0.00142607425712026 </td><td>2.63678996921613    </td><td>0.00836954621901576 </td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 2                    & -0.00321116368682407 & 0.00143408392286025  & -2.23917417637558    & 0.0251447255715103   & 1562314              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 2                    & 0.00376025829653205  & 0.00142607425712026  & 2.63678996921613     & 0.00836954621901576  & 1562314              & rider/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 2                    | -0.00321116368682407 | 0.00143408392286025  | -2.23917417637558    | 0.0251447255715103   | 1562314              | rider/date/commute   |\n",
       "| imputed_new_buses:single_stop_10_ride | 2                    | 0.00376025829653205  | 0.00142607425712026  | 2.63678996921613     | 0.00836954621901576  | 1562314              | rider/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "                                      model Estimate            \n",
       "imputed_new_buses                     2     -0.00321116368682407\n",
       "imputed_new_buses:single_stop_10_ride 2     0.00376025829653205 \n",
       "                                      Std. Error          t value          \n",
       "imputed_new_buses                     0.00143408392286025 -2.23917417637558\n",
       "imputed_new_buses:single_stop_10_ride 0.00142607425712026 2.63678996921613 \n",
       "                                      Pr(>|t|)            N      \n",
       "imputed_new_buses                     0.0251447255715103  1562314\n",
       "imputed_new_buses:single_stop_10_ride 0.00836954621901576 1562314\n",
       "                                      granularity       \n",
       "imputed_new_buses                     rider/date/commute\n",
       "imputed_new_buses:single_stop_10_ride rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(T4_M2 = fit_ridership_logit_models(data = commute_ride_data,\n",
    "                            predictors=c(\"imputed_new_buses\",\n",
    "                                            \"imputed_new_buses:single_stop_10_ride\"\n",
    "                                        ),\n",
    "                            adjust_for=c(\"imputed_new_buses + fDate\",\n",
    "                                            \"f_commutes_since_last_ride\",\n",
    "                                            \"f_favorite_route\"),\n",
    "                            model=2,\n",
    "                            granularity=\"rider/date/commute\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  3 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                                 Estimate  Std. Error\n",
      "imputed_new_buses                             0.001864539 0.001553662\n",
      "Is405North_10_ride:I405HOV                    0.008051068 0.013144501\n",
      "imputed_new_buses:I405HOV                    -0.005408516 0.001032780\n",
      "imputed_new_buses:Is405North_10_ride         -0.010819330 0.003044288\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV -0.011652471 0.013537167\n",
      "                                                t value     Pr(>|t|)\n",
      "imputed_new_buses                             1.2000933 2.301033e-01\n",
      "Is405North_10_ride:I405HOV                    0.6125047 5.402040e-01\n",
      "imputed_new_buses:I405HOV                    -5.2368507 1.633608e-07\n",
      "imputed_new_buses:Is405North_10_ride         -3.5539771 3.794634e-04\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV -0.8607762 3.893615e-01\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>3                   </td><td>0.00186453949950805 </td><td>0.00155366210463195 </td><td>1.20009331111912    </td><td>0.230103285047142   </td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>3                   </td><td>0.00805106770841493 </td><td>0.0131445005284482  </td><td>0.612504650974776   </td><td>0.540204010933492   </td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:I405HOV</th><td>3                   </td><td>-0.00540851557867988</td><td>0.00103278017274737 </td><td>-5.23685070782518   </td><td>1.63360786491143e-07</td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride</th><td>3                   </td><td>-0.0108193301379585 </td><td>0.00304428805290009 </td><td>-3.55397713683883   </td><td>0.000379463385844024</td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>3                   </td><td>-0.0116524709942686 </td><td>0.0135371668977361  </td><td>-0.860776193593157  </td><td>0.389361451207431   </td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 3                    & 0.00186453949950805  & 0.00155366210463195  & 1.20009331111912     & 0.230103285047142    & 1562314              & rider/date/commute  \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 3                    & 0.00805106770841493  & 0.0131445005284482   & 0.612504650974776    & 0.540204010933492    & 1562314              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:I405HOV & 3                    & -0.00540851557867988 & 0.00103278017274737  & -5.23685070782518    & 1.63360786491143e-07 & 1562314              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride & 3                    & -0.0108193301379585  & 0.00304428805290009  & -3.55397713683883    & 0.000379463385844024 & 1562314              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 3                    & -0.0116524709942686  & 0.0135371668977361   & -0.860776193593157   & 0.389361451207431    & 1562314              & rider/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 3                    | 0.00186453949950805  | 0.00155366210463195  | 1.20009331111912     | 0.230103285047142    | 1562314              | rider/date/commute   |\n",
       "| Is405North_10_ride:I405HOV | 3                    | 0.00805106770841493  | 0.0131445005284482   | 0.612504650974776    | 0.540204010933492    | 1562314              | rider/date/commute   |\n",
       "| imputed_new_buses:I405HOV | 3                    | -0.00540851557867988 | 0.00103278017274737  | -5.23685070782518    | 1.63360786491143e-07 | 1562314              | rider/date/commute   |\n",
       "| imputed_new_buses:Is405North_10_ride | 3                    | -0.0108193301379585  | 0.00304428805290009  | -3.55397713683883    | 0.000379463385844024 | 1562314              | rider/date/commute   |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 3                    | -0.0116524709942686  | 0.0135371668977361   | -0.860776193593157   | 0.389361451207431    | 1562314              | rider/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "                                             model Estimate            \n",
       "imputed_new_buses                            3     0.00186453949950805 \n",
       "Is405North_10_ride:I405HOV                   3     0.00805106770841493 \n",
       "imputed_new_buses:I405HOV                    3     -0.00540851557867988\n",
       "imputed_new_buses:Is405North_10_ride         3     -0.0108193301379585 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV 3     -0.0116524709942686 \n",
       "                                             Std. Error         \n",
       "imputed_new_buses                            0.00155366210463195\n",
       "Is405North_10_ride:I405HOV                   0.0131445005284482 \n",
       "imputed_new_buses:I405HOV                    0.00103278017274737\n",
       "imputed_new_buses:Is405North_10_ride         0.00304428805290009\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV 0.0135371668977361 \n",
       "                                             t value           \n",
       "imputed_new_buses                            1.20009331111912  \n",
       "Is405North_10_ride:I405HOV                   0.612504650974776 \n",
       "imputed_new_buses:I405HOV                    -5.23685070782518 \n",
       "imputed_new_buses:Is405North_10_ride         -3.55397713683883 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV -0.860776193593157\n",
       "                                             Pr(>|t|)             N      \n",
       "imputed_new_buses                            0.230103285047142    1562314\n",
       "Is405North_10_ride:I405HOV                   0.540204010933492    1562314\n",
       "imputed_new_buses:I405HOV                    1.63360786491143e-07 1562314\n",
       "imputed_new_buses:Is405North_10_ride         0.000379463385844024 1562314\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV 0.389361451207431    1562314\n",
       "                                             granularity       \n",
       "imputed_new_buses                            rider/date/commute\n",
       "Is405North_10_ride:I405HOV                   rider/date/commute\n",
       "imputed_new_buses:I405HOV                    rider/date/commute\n",
       "imputed_new_buses:Is405North_10_ride         rider/date/commute\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(T4_M3 = fit_ridership_logit_models(data = commute_ride_data,\n",
    "                            predictors=c(\n",
    "                                        \"imputed_new_buses\",\n",
    "                                        \"Is405North_10_ride:I405HOV\",\n",
    "                                        \"imputed_new_buses:I405HOV\",\n",
    "                                        \"imputed_new_buses:Is405North_10_ride\",\n",
    "                                        \"imputed_new_buses:Is405North_10_ride:I405HOV\"\n",
    "                                        ),\n",
    "                            adjust_for=c(\"imputed_new_buses + fDate\",\n",
    "                                            \"f_commutes_since_last_ride\",\n",
    "                                            \"f_favorite_route\"),\n",
    "                            model=3,\n",
    "                            granularity=\"rider/date/commute\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  4 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                                   Estimate  Std. Error\n",
      "imputed_new_buses                              -0.003130244 0.001448300\n",
      "imputed_new_buses:single_stop_10_ride           0.005097348 0.001579034\n",
      "Is405North_10_ride:I405HOV                      0.018024944 0.012929228\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV   -0.024705343 0.013219034\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV -0.005244977 0.002956165\n",
      "                                                 t value    Pr(>|t|)\n",
      "imputed_new_buses                              -2.161323 0.030670567\n",
      "imputed_new_buses:single_stop_10_ride           3.228143 0.001245994\n",
      "Is405North_10_ride:I405HOV                      1.394124 0.163280432\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV   -1.868922 0.061633855\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV -1.774251 0.076021915\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>4                   </td><td>-0.00313024397500519</td><td>0.00144830009696747 </td><td>-2.16132276836787   </td><td>0.030670566774478   </td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>4                   </td><td>0.0050973475024661  </td><td>0.00157903415268111 </td><td>3.22814265531313    </td><td>0.00124599392094918 </td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>4                   </td><td>0.0180249440209423  </td><td>0.0129292280029139  </td><td>1.39412376492084    </td><td>0.163280432195932   </td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>4                   </td><td>-0.0247053433516312 </td><td>0.0132190339863928  </td><td>-1.86892199362389   </td><td>0.0616338549236592  </td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>4                   </td><td>-0.00524497716585718</td><td>0.00295616492007067 </td><td>-1.77425052650032   </td><td>0.0760219147319243  </td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 4                    & -0.00313024397500519 & 0.00144830009696747  & -2.16132276836787    & 0.030670566774478    & 1562314              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 4                    & 0.0050973475024661   & 0.00157903415268111  & 3.22814265531313     & 0.00124599392094918  & 1562314              & rider/date/commute  \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 4                    & 0.0180249440209423   & 0.0129292280029139   & 1.39412376492084     & 0.163280432195932    & 1562314              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 4                    & -0.0247053433516312  & 0.0132190339863928   & -1.86892199362389    & 0.0616338549236592   & 1562314              & rider/date/commute  \\\\\n",
       "\tsingle\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 4                    & -0.00524497716585718 & 0.00295616492007067  & -1.77425052650032    & 0.0760219147319243   & 1562314              & rider/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 4                    | -0.00313024397500519 | 0.00144830009696747  | -2.16132276836787    | 0.030670566774478    | 1562314              | rider/date/commute   |\n",
       "| imputed_new_buses:single_stop_10_ride | 4                    | 0.0050973475024661   | 0.00157903415268111  | 3.22814265531313     | 0.00124599392094918  | 1562314              | rider/date/commute   |\n",
       "| Is405North_10_ride:I405HOV | 4                    | 0.0180249440209423   | 0.0129292280029139   | 1.39412376492084     | 0.163280432195932    | 1562314              | rider/date/commute   |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 4                    | -0.0247053433516312  | 0.0132190339863928   | -1.86892199362389    | 0.0616338549236592   | 1562314              | rider/date/commute   |\n",
       "| single_stop_10_ride:Is405North_10_ride:I405HOV | 4                    | -0.00524497716585718 | 0.00295616492007067  | -1.77425052650032    | 0.0760219147319243   | 1562314              | rider/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "                                               model Estimate            \n",
       "imputed_new_buses                              4     -0.00313024397500519\n",
       "imputed_new_buses:single_stop_10_ride          4     0.0050973475024661  \n",
       "Is405North_10_ride:I405HOV                     4     0.0180249440209423  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   4     -0.0247053433516312 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV 4     -0.00524497716585718\n",
       "                                               Std. Error         \n",
       "imputed_new_buses                              0.00144830009696747\n",
       "imputed_new_buses:single_stop_10_ride          0.00157903415268111\n",
       "Is405North_10_ride:I405HOV                     0.0129292280029139 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   0.0132190339863928 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV 0.00295616492007067\n",
       "                                               t value          \n",
       "imputed_new_buses                              -2.16132276836787\n",
       "imputed_new_buses:single_stop_10_ride          3.22814265531313 \n",
       "Is405North_10_ride:I405HOV                     1.39412376492084 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   -1.86892199362389\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV -1.77425052650032\n",
       "                                               Pr(>|t|)            N      \n",
       "imputed_new_buses                              0.030670566774478   1562314\n",
       "imputed_new_buses:single_stop_10_ride          0.00124599392094918 1562314\n",
       "Is405North_10_ride:I405HOV                     0.163280432195932   1562314\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   0.0616338549236592  1562314\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV 0.0760219147319243  1562314\n",
       "                                               granularity       \n",
       "imputed_new_buses                              rider/date/commute\n",
       "imputed_new_buses:single_stop_10_ride          rider/date/commute\n",
       "Is405North_10_ride:I405HOV                     rider/date/commute\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV   rider/date/commute\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(T4_M4 = fit_ridership_logit_models(data = commute_ride_data,\n",
    "                            predictors=c(\n",
    "                                        \"imputed_new_buses\",\n",
    "                                        \"imputed_new_buses:single_stop_10_ride\",\n",
    "                                        \"Is405North_10_ride:I405HOV\",\n",
    "                                        \"imputed_new_buses:Is405North_10_ride:I405HOV\",\n",
    "                                        \"single_stop_10_ride:Is405North_10_ride:I405HOV\"\n",
    "                                        ),\n",
    "                            adjust_for=c(\"imputed_new_buses + fDate\",\n",
    "                                            \"f_commutes_since_last_ride\",\n",
    "                                            \"f_favorite_route\"),\n",
    "                            model=4,\n",
    "                            granularity=\"rider/date/commute\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "===============================================\n",
      "Model  5 :\n",
      "===============================================\n",
      "\n",
      "\n",
      "Coefficients from Linear model (adjust_for effects omitted):\n",
      "                                                                     Estimate\n",
      "imputed_new_buses                                                -0.003135152\n",
      "imputed_new_buses:single_stop_10_ride                             0.005331171\n",
      "Is405North_10_ride:I405HOV                                       -0.027336170\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV                      0.021951757\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV                    0.198927439\n",
      "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -0.209558057\n",
      "                                                                  Std. Error\n",
      "imputed_new_buses                                                0.001448290\n",
      "imputed_new_buses:single_stop_10_ride                            0.001579777\n",
      "Is405North_10_ride:I405HOV                                       0.016024197\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV                     0.016417868\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.042711018\n",
      "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.043732519\n",
      "                                                                   t value\n",
      "imputed_new_buses                                                -2.164726\n",
      "imputed_new_buses:single_stop_10_ride                             3.374636\n",
      "Is405North_10_ride:I405HOV                                       -1.705931\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV                      1.337065\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV                    4.657520\n",
      "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -4.791813\n",
      "                                                                     Pr(>|t|)\n",
      "imputed_new_buses                                                3.040880e-02\n",
      "imputed_new_buses:single_stop_10_ride                            7.391531e-04\n",
      "Is405North_10_ride:I405HOV                                       8.802118e-02\n",
      "imputed_new_buses:Is405North_10_ride:I405HOV                     1.812016e-01\n",
      "single_stop_10_ride:Is405North_10_ride:I405HOV                   3.200669e-06\n",
      "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 1.652960e-06\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>5                   </td><td>-0.00313515212030744</td><td>0.00144829027796469 </td><td>-2.16472634526922   </td><td>0.0304087992394261  </td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>5                   </td><td>0.00533117105449336 </td><td>0.00157977684988739 </td><td>3.37463550935904    </td><td>0.000739153129605849</td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>5                   </td><td>-0.0273361698974266 </td><td>0.0160241973183143  </td><td>-1.7059306843522    </td><td>0.0880211847533962  </td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>5                   </td><td>0.0219517573400444  </td><td>0.016417867990816   </td><td>1.33706504110789    </td><td>0.181201601870555   </td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>5                   </td><td>0.198927439216159   </td><td>0.0427110179776392  </td><td>4.65752043934669    </td><td>3.20066947209648e-06</td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>5                   </td><td>-0.209558056589303  </td><td>0.0437325191918307  </td><td>-4.79181305952412   </td><td>1.65296013170764e-06</td><td>1562314             </td><td>rider/date/commute  </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & N & granularity\\\\\n",
       "\\hline\n",
       "\timputed\\_new\\_buses & 5                    & -0.00313515212030744 & 0.00144829027796469  & -2.16472634526922    & 0.0304087992394261   & 1562314              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 5                    & 0.00533117105449336  & 0.00157977684988739  & 3.37463550935904     & 0.000739153129605849 & 1562314              & rider/date/commute  \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 5                    & -0.0273361698974266  & 0.0160241973183143   & -1.7059306843522     & 0.0880211847533962   & 1562314              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 5                    & 0.0219517573400444   & 0.016417867990816    & 1.33706504110789     & 0.181201601870555    & 1562314              & rider/date/commute  \\\\\n",
       "\tsingle\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 5                    & 0.198927439216159    & 0.0427110179776392   & 4.65752043934669     & 3.20066947209648e-06 & 1562314              & rider/date/commute  \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 5                    & -0.209558056589303   & 0.0437325191918307   & -4.79181305952412    & 1.65296013170764e-06 & 1562314              & rider/date/commute  \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "| imputed_new_buses | 5                    | -0.00313515212030744 | 0.00144829027796469  | -2.16472634526922    | 0.0304087992394261   | 1562314              | rider/date/commute   |\n",
       "| imputed_new_buses:single_stop_10_ride | 5                    | 0.00533117105449336  | 0.00157977684988739  | 3.37463550935904     | 0.000739153129605849 | 1562314              | rider/date/commute   |\n",
       "| Is405North_10_ride:I405HOV | 5                    | -0.0273361698974266  | 0.0160241973183143   | -1.7059306843522     | 0.0880211847533962   | 1562314              | rider/date/commute   |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 5                    | 0.0219517573400444   | 0.016417867990816    | 1.33706504110789     | 0.181201601870555    | 1562314              | rider/date/commute   |\n",
       "| single_stop_10_ride:Is405North_10_ride:I405HOV | 5                    | 0.198927439216159    | 0.0427110179776392   | 4.65752043934669     | 3.20066947209648e-06 | 1562314              | rider/date/commute   |\n",
       "| imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV | 5                    | -0.209558056589303   | 0.0437325191918307   | -4.79181305952412    | 1.65296013170764e-06 | 1562314              | rider/date/commute   |\n",
       "\n"
      ],
      "text/plain": [
       "                                                                 model\n",
       "imputed_new_buses                                                5    \n",
       "imputed_new_buses:single_stop_10_ride                            5    \n",
       "Is405North_10_ride:I405HOV                                       5    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     5    \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   5    \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 5    \n",
       "                                                                 Estimate            \n",
       "imputed_new_buses                                                -0.00313515212030744\n",
       "imputed_new_buses:single_stop_10_ride                            0.00533117105449336 \n",
       "Is405North_10_ride:I405HOV                                       -0.0273361698974266 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.0219517573400444  \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.198927439216159   \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -0.209558056589303  \n",
       "                                                                 Std. Error         \n",
       "imputed_new_buses                                                0.00144829027796469\n",
       "imputed_new_buses:single_stop_10_ride                            0.00157977684988739\n",
       "Is405North_10_ride:I405HOV                                       0.0160241973183143 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.016417867990816  \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.0427110179776392 \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.0437325191918307 \n",
       "                                                                 t value          \n",
       "imputed_new_buses                                                -2.16472634526922\n",
       "imputed_new_buses:single_stop_10_ride                            3.37463550935904 \n",
       "Is405North_10_ride:I405HOV                                       -1.7059306843522 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     1.33706504110789 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   4.65752043934669 \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -4.79181305952412\n",
       "                                                                 Pr(>|t|)            \n",
       "imputed_new_buses                                                0.0304087992394261  \n",
       "imputed_new_buses:single_stop_10_ride                            0.000739153129605849\n",
       "Is405North_10_ride:I405HOV                                       0.0880211847533962  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.181201601870555   \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   3.20066947209648e-06\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 1.65296013170764e-06\n",
       "                                                                 N      \n",
       "imputed_new_buses                                                1562314\n",
       "imputed_new_buses:single_stop_10_ride                            1562314\n",
       "Is405North_10_ride:I405HOV                                       1562314\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     1562314\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   1562314\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 1562314\n",
       "                                                                 granularity       \n",
       "imputed_new_buses                                                rider/date/commute\n",
       "imputed_new_buses:single_stop_10_ride                            rider/date/commute\n",
       "Is405North_10_ride:I405HOV                                       rider/date/commute\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     rider/date/commute\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   rider/date/commute\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV rider/date/commute"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(T4_M5 = fit_ridership_logit_models(data = commute_ride_data,\n",
    "                            predictors=c(\n",
    "                                        \"imputed_new_buses\",\n",
    "                                        \"imputed_new_buses:single_stop_10_ride\",\n",
    "                                        \"Is405North_10_ride:I405HOV\",\n",
    "                                        \"imputed_new_buses:Is405North_10_ride:I405HOV\",\n",
    "                                        \"single_stop_10_ride:Is405North_10_ride:I405HOV\",\n",
    "                                        \"imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV\"\n",
    "                                        ),\n",
    "                            adjust_for=c(\"imputed_new_buses + fDate\",\n",
    "                                            \"f_commutes_since_last_ride\",\n",
    "                                            \"f_favorite_route\"),\n",
    "                            model=5,\n",
    "                            granularity=\"rider/date/commute\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Table 4 Summary Statistics"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table>\n",
       "<thead><tr><th></th><th scope=col>model</th><th scope=col>Estimate</th><th scope=col>Std. Error</th><th scope=col>t value</th><th scope=col>Pr(&gt;|t|)</th><th scope=col>N</th><th scope=col>granularity</th></tr></thead>\n",
       "<tbody>\n",
       "\t<tr><th scope=row></th><td>1                                                </td><td>0.00682045906585944                              </td><td>0.00302167320935502                              </td><td>2.25717958008943                                 </td><td>0.0239979625757054                               </td><td>194386                                           </td><td>rider/date/commute [Single Stop Preferred Riders]</td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>2                                                </td><td>-0.00321116368682407                             </td><td>0.00143408392286025                              </td><td>-2.23917417637558                                </td><td>0.0251447255715103                               </td><td>1562314                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>2                                                </td><td>0.00376025829653205                              </td><td>0.00142607425712026                              </td><td>2.63678996921613                                 </td><td>0.00836954621901576                              </td><td>1562314                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>3                                                </td><td>0.00186453949950805                              </td><td>0.00155366210463195                              </td><td>1.20009331111912                                 </td><td>0.230103285047142                                </td><td>1562314                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>3                                                </td><td>0.00805106770841493                              </td><td>0.0131445005284482                               </td><td>0.612504650974776                                </td><td>0.540204010933492                                </td><td>1562314                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:I405HOV</th><td>3                                                </td><td>-0.00540851557867988                             </td><td>0.00103278017274737                              </td><td>-5.23685070782518                                </td><td>1.63360786491143e-07                             </td><td>1562314                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride</th><td>3                                                </td><td>-0.0108193301379585                              </td><td>0.00304428805290009                              </td><td>-3.55397713683883                                </td><td>0.000379463385844024                             </td><td>1562314                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>3                                                </td><td>-0.0116524709942686                              </td><td>0.0135371668977361                               </td><td>-0.860776193593157                               </td><td>0.389361451207431                                </td><td>1562314                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>4                                                </td><td>-0.00313024397500519                             </td><td>0.00144830009696747                              </td><td>-2.16132276836787                                </td><td>0.030670566774478                                </td><td>1562314                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>4                                                </td><td>0.0050973475024661                               </td><td>0.00157903415268111                              </td><td>3.22814265531313                                 </td><td>0.00124599392094918                              </td><td>1562314                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>4                                                </td><td>0.0180249440209423                               </td><td>0.0129292280029139                               </td><td>1.39412376492084                                 </td><td>0.163280432195932                                </td><td>1562314                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>4                                                </td><td>-0.0247053433516312                              </td><td>0.0132190339863928                               </td><td>-1.86892199362389                                </td><td>0.0616338549236592                               </td><td>1562314                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>4                                                </td><td>-0.00524497716585718                             </td><td>0.00295616492007067                              </td><td>-1.77425052650032                                </td><td>0.0760219147319243                               </td><td>1562314                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses</th><td>5                                                </td><td>-0.00313515212030744                             </td><td>0.00144829027796469                              </td><td>-2.16472634526922                                </td><td>0.0304087992394261                               </td><td>1562314                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride</th><td>5                                                </td><td>0.00533117105449336                              </td><td>0.00157977684988739                              </td><td>3.37463550935904                                 </td><td>0.000739153129605849                             </td><td>1562314                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>Is405North_10_ride:I405HOV</th><td>5                                                </td><td>-0.0273361698974266                              </td><td>0.0160241973183143                               </td><td>-1.7059306843522                                 </td><td>0.0880211847533962                               </td><td>1562314                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:Is405North_10_ride:I405HOV</th><td>5                                                </td><td>0.0219517573400444                               </td><td>0.016417867990816                                </td><td>1.33706504110789                                 </td><td>0.181201601870555                                </td><td>1562314                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>5                                                </td><td>0.198927439216159                                </td><td>0.0427110179776392                               </td><td>4.65752043934669                                 </td><td>3.20066947209648e-06                             </td><td>1562314                                          </td><td>rider/date/commute                               </td></tr>\n",
       "\t<tr><th scope=row>imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV</th><td>5                                                </td><td>-0.209558056589303                               </td><td>0.0437325191918307                               </td><td>-4.79181305952412                                </td><td>1.65296013170764e-06                             </td><td>1562314                                          </td><td>rider/date/commute                               </td></tr>\n",
       "</tbody>\n",
       "</table>\n"
      ],
      "text/latex": [
       "\\begin{tabular}{r|lllllll}\n",
       "  & model & Estimate & Std. Error & t value & Pr(>\\textbar{}t\\textbar{}) & N & granularity\\\\\n",
       "\\hline\n",
       "\t & 1                                                     & 0.00682045906585944                                   & 0.00302167320935502                                   & 2.25717958008943                                      & 0.0239979625757054                                    & 194386                                                & rider/date/commute {[}Single Stop Preferred Riders{]}\\\\\n",
       "\timputed\\_new\\_buses & 2                                                 & -0.00321116368682407                              & 0.00143408392286025                               & -2.23917417637558                                 & 0.0251447255715103                                & 1562314                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 2                                                 & 0.00376025829653205                               & 0.00142607425712026                               & 2.63678996921613                                  & 0.00836954621901576                               & 1562314                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses & 3                                                 & 0.00186453949950805                               & 0.00155366210463195                               & 1.20009331111912                                  & 0.230103285047142                                 & 1562314                                           & rider/date/commute                               \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 3                                                 & 0.00805106770841493                               & 0.0131445005284482                                & 0.612504650974776                                 & 0.540204010933492                                 & 1562314                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:I405HOV & 3                                                 & -0.00540851557867988                              & 0.00103278017274737                               & -5.23685070782518                                 & 1.63360786491143e-07                              & 1562314                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride & 3                                                 & -0.0108193301379585                               & 0.00304428805290009                               & -3.55397713683883                                 & 0.000379463385844024                              & 1562314                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 3                                                 & -0.0116524709942686                               & 0.0135371668977361                                & -0.860776193593157                                & 0.389361451207431                                 & 1562314                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses & 4                                                 & -0.00313024397500519                              & 0.00144830009696747                               & -2.16132276836787                                 & 0.030670566774478                                 & 1562314                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 4                                                 & 0.0050973475024661                                & 0.00157903415268111                               & 3.22814265531313                                  & 0.00124599392094918                               & 1562314                                           & rider/date/commute                               \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 4                                                 & 0.0180249440209423                                & 0.0129292280029139                                & 1.39412376492084                                  & 0.163280432195932                                 & 1562314                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 4                                                 & -0.0247053433516312                               & 0.0132190339863928                                & -1.86892199362389                                 & 0.0616338549236592                                & 1562314                                           & rider/date/commute                               \\\\\n",
       "\tsingle\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 4                                                 & -0.00524497716585718                              & 0.00295616492007067                               & -1.77425052650032                                 & 0.0760219147319243                                & 1562314                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses & 5                                                 & -0.00313515212030744                              & 0.00144829027796469                               & -2.16472634526922                                 & 0.0304087992394261                                & 1562314                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride & 5                                                 & 0.00533117105449336                               & 0.00157977684988739                               & 3.37463550935904                                  & 0.000739153129605849                              & 1562314                                           & rider/date/commute                               \\\\\n",
       "\tIs405North\\_10\\_ride:I405HOV & 5                                                 & -0.0273361698974266                               & 0.0160241973183143                                & -1.7059306843522                                  & 0.0880211847533962                                & 1562314                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:Is405North\\_10\\_ride:I405HOV & 5                                                 & 0.0219517573400444                                & 0.016417867990816                                 & 1.33706504110789                                  & 0.181201601870555                                 & 1562314                                           & rider/date/commute                               \\\\\n",
       "\tsingle\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 5                                                 & 0.198927439216159                                 & 0.0427110179776392                                & 4.65752043934669                                  & 3.20066947209648e-06                              & 1562314                                           & rider/date/commute                               \\\\\n",
       "\timputed\\_new\\_buses:single\\_stop\\_10\\_ride:Is405North\\_10\\_ride:I405HOV & 5                                                 & -0.209558056589303                                & 0.0437325191918307                                & -4.79181305952412                                 & 1.65296013170764e-06                              & 1562314                                           & rider/date/commute                               \\\\\n",
       "\\end{tabular}\n"
      ],
      "text/markdown": [
       "\n",
       "| <!--/--> | model | Estimate | Std. Error | t value | Pr(>|t|) | N | granularity |\n",
       "|---|---|---|---|---|---|---|---|\n",
       "|  | 1                                                 | 0.00682045906585944                               | 0.00302167320935502                               | 2.25717958008943                                  | 0.0239979625757054                                | 194386                                            | rider/date/commute [Single Stop Preferred Riders] |\n",
       "| imputed_new_buses | 2                                                 | -0.00321116368682407                              | 0.00143408392286025                               | -2.23917417637558                                 | 0.0251447255715103                                | 1562314                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:single_stop_10_ride | 2                                                 | 0.00376025829653205                               | 0.00142607425712026                               | 2.63678996921613                                  | 0.00836954621901576                               | 1562314                                           | rider/date/commute                                |\n",
       "| imputed_new_buses | 3                                                 | 0.00186453949950805                               | 0.00155366210463195                               | 1.20009331111912                                  | 0.230103285047142                                 | 1562314                                           | rider/date/commute                                |\n",
       "| Is405North_10_ride:I405HOV | 3                                                 | 0.00805106770841493                               | 0.0131445005284482                                | 0.612504650974776                                 | 0.540204010933492                                 | 1562314                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:I405HOV | 3                                                 | -0.00540851557867988                              | 0.00103278017274737                               | -5.23685070782518                                 | 1.63360786491143e-07                              | 1562314                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:Is405North_10_ride | 3                                                 | -0.0108193301379585                               | 0.00304428805290009                               | -3.55397713683883                                 | 0.000379463385844024                              | 1562314                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 3                                                 | -0.0116524709942686                               | 0.0135371668977361                                | -0.860776193593157                                | 0.389361451207431                                 | 1562314                                           | rider/date/commute                                |\n",
       "| imputed_new_buses | 4                                                 | -0.00313024397500519                              | 0.00144830009696747                               | -2.16132276836787                                 | 0.030670566774478                                 | 1562314                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:single_stop_10_ride | 4                                                 | 0.0050973475024661                                | 0.00157903415268111                               | 3.22814265531313                                  | 0.00124599392094918                               | 1562314                                           | rider/date/commute                                |\n",
       "| Is405North_10_ride:I405HOV | 4                                                 | 0.0180249440209423                                | 0.0129292280029139                                | 1.39412376492084                                  | 0.163280432195932                                 | 1562314                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 4                                                 | -0.0247053433516312                               | 0.0132190339863928                                | -1.86892199362389                                 | 0.0616338549236592                                | 1562314                                           | rider/date/commute                                |\n",
       "| single_stop_10_ride:Is405North_10_ride:I405HOV | 4                                                 | -0.00524497716585718                              | 0.00295616492007067                               | -1.77425052650032                                 | 0.0760219147319243                                | 1562314                                           | rider/date/commute                                |\n",
       "| imputed_new_buses | 5                                                 | -0.00313515212030744                              | 0.00144829027796469                               | -2.16472634526922                                 | 0.0304087992394261                                | 1562314                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:single_stop_10_ride | 5                                                 | 0.00533117105449336                               | 0.00157977684988739                               | 3.37463550935904                                  | 0.000739153129605849                              | 1562314                                           | rider/date/commute                                |\n",
       "| Is405North_10_ride:I405HOV | 5                                                 | -0.0273361698974266                               | 0.0160241973183143                                | -1.7059306843522                                  | 0.0880211847533962                                | 1562314                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:Is405North_10_ride:I405HOV | 5                                                 | 0.0219517573400444                                | 0.016417867990816                                 | 1.33706504110789                                  | 0.181201601870555                                 | 1562314                                           | rider/date/commute                                |\n",
       "| single_stop_10_ride:Is405North_10_ride:I405HOV | 5                                                 | 0.198927439216159                                 | 0.0427110179776392                                | 4.65752043934669                                  | 3.20066947209648e-06                              | 1562314                                           | rider/date/commute                                |\n",
       "| imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV | 5                                                 | -0.209558056589303                                | 0.0437325191918307                                | -4.79181305952412                                 | 1.65296013170764e-06                              | 1562314                                           | rider/date/commute                                |\n",
       "\n"
      ],
      "text/plain": [
       "                                                                 model\n",
       "                                                                 1    \n",
       "imputed_new_buses                                                2    \n",
       "imputed_new_buses:single_stop_10_ride                            2    \n",
       "imputed_new_buses                                                3    \n",
       "Is405North_10_ride:I405HOV                                       3    \n",
       "imputed_new_buses:I405HOV                                        3    \n",
       "imputed_new_buses:Is405North_10_ride                             3    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     3    \n",
       "imputed_new_buses                                                4    \n",
       "imputed_new_buses:single_stop_10_ride                            4    \n",
       "Is405North_10_ride:I405HOV                                       4    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     4    \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   4    \n",
       "imputed_new_buses                                                5    \n",
       "imputed_new_buses:single_stop_10_ride                            5    \n",
       "Is405North_10_ride:I405HOV                                       5    \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     5    \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   5    \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 5    \n",
       "                                                                 Estimate            \n",
       "                                                                 0.00682045906585944 \n",
       "imputed_new_buses                                                -0.00321116368682407\n",
       "imputed_new_buses:single_stop_10_ride                            0.00376025829653205 \n",
       "imputed_new_buses                                                0.00186453949950805 \n",
       "Is405North_10_ride:I405HOV                                       0.00805106770841493 \n",
       "imputed_new_buses:I405HOV                                        -0.00540851557867988\n",
       "imputed_new_buses:Is405North_10_ride                             -0.0108193301379585 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.0116524709942686 \n",
       "imputed_new_buses                                                -0.00313024397500519\n",
       "imputed_new_buses:single_stop_10_ride                            0.0050973475024661  \n",
       "Is405North_10_ride:I405HOV                                       0.0180249440209423  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.0247053433516312 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   -0.00524497716585718\n",
       "imputed_new_buses                                                -0.00313515212030744\n",
       "imputed_new_buses:single_stop_10_ride                            0.00533117105449336 \n",
       "Is405North_10_ride:I405HOV                                       -0.0273361698974266 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.0219517573400444  \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.198927439216159   \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -0.209558056589303  \n",
       "                                                                 Std. Error         \n",
       "                                                                 0.00302167320935502\n",
       "imputed_new_buses                                                0.00143408392286025\n",
       "imputed_new_buses:single_stop_10_ride                            0.00142607425712026\n",
       "imputed_new_buses                                                0.00155366210463195\n",
       "Is405North_10_ride:I405HOV                                       0.0131445005284482 \n",
       "imputed_new_buses:I405HOV                                        0.00103278017274737\n",
       "imputed_new_buses:Is405North_10_ride                             0.00304428805290009\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.0135371668977361 \n",
       "imputed_new_buses                                                0.00144830009696747\n",
       "imputed_new_buses:single_stop_10_ride                            0.00157903415268111\n",
       "Is405North_10_ride:I405HOV                                       0.0129292280029139 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.0132190339863928 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.00295616492007067\n",
       "imputed_new_buses                                                0.00144829027796469\n",
       "imputed_new_buses:single_stop_10_ride                            0.00157977684988739\n",
       "Is405North_10_ride:I405HOV                                       0.0160241973183143 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.016417867990816  \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.0427110179776392 \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 0.0437325191918307 \n",
       "                                                                 t value           \n",
       "                                                                 2.25717958008943  \n",
       "imputed_new_buses                                                -2.23917417637558 \n",
       "imputed_new_buses:single_stop_10_ride                            2.63678996921613  \n",
       "imputed_new_buses                                                1.20009331111912  \n",
       "Is405North_10_ride:I405HOV                                       0.612504650974776 \n",
       "imputed_new_buses:I405HOV                                        -5.23685070782518 \n",
       "imputed_new_buses:Is405North_10_ride                             -3.55397713683883 \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -0.860776193593157\n",
       "imputed_new_buses                                                -2.16132276836787 \n",
       "imputed_new_buses:single_stop_10_ride                            3.22814265531313  \n",
       "Is405North_10_ride:I405HOV                                       1.39412376492084  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     -1.86892199362389 \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   -1.77425052650032 \n",
       "imputed_new_buses                                                -2.16472634526922 \n",
       "imputed_new_buses:single_stop_10_ride                            3.37463550935904  \n",
       "Is405North_10_ride:I405HOV                                       -1.7059306843522  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     1.33706504110789  \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   4.65752043934669  \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV -4.79181305952412 \n",
       "                                                                 Pr(>|t|)            \n",
       "                                                                 0.0239979625757054  \n",
       "imputed_new_buses                                                0.0251447255715103  \n",
       "imputed_new_buses:single_stop_10_ride                            0.00836954621901576 \n",
       "imputed_new_buses                                                0.230103285047142   \n",
       "Is405North_10_ride:I405HOV                                       0.540204010933492   \n",
       "imputed_new_buses:I405HOV                                        1.63360786491143e-07\n",
       "imputed_new_buses:Is405North_10_ride                             0.000379463385844024\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.389361451207431   \n",
       "imputed_new_buses                                                0.030670566774478   \n",
       "imputed_new_buses:single_stop_10_ride                            0.00124599392094918 \n",
       "Is405North_10_ride:I405HOV                                       0.163280432195932   \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.0616338549236592  \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   0.0760219147319243  \n",
       "imputed_new_buses                                                0.0304087992394261  \n",
       "imputed_new_buses:single_stop_10_ride                            0.000739153129605849\n",
       "Is405North_10_ride:I405HOV                                       0.0880211847533962  \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     0.181201601870555   \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   3.20066947209648e-06\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 1.65296013170764e-06\n",
       "                                                                 N      \n",
       "                                                                 194386 \n",
       "imputed_new_buses                                                1562314\n",
       "imputed_new_buses:single_stop_10_ride                            1562314\n",
       "imputed_new_buses                                                1562314\n",
       "Is405North_10_ride:I405HOV                                       1562314\n",
       "imputed_new_buses:I405HOV                                        1562314\n",
       "imputed_new_buses:Is405North_10_ride                             1562314\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     1562314\n",
       "imputed_new_buses                                                1562314\n",
       "imputed_new_buses:single_stop_10_ride                            1562314\n",
       "Is405North_10_ride:I405HOV                                       1562314\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     1562314\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   1562314\n",
       "imputed_new_buses                                                1562314\n",
       "imputed_new_buses:single_stop_10_ride                            1562314\n",
       "Is405North_10_ride:I405HOV                                       1562314\n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     1562314\n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   1562314\n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV 1562314\n",
       "                                                                 granularity                                      \n",
       "                                                                 rider/date/commute [Single Stop Preferred Riders]\n",
       "imputed_new_buses                                                rider/date/commute                               \n",
       "imputed_new_buses:single_stop_10_ride                            rider/date/commute                               \n",
       "imputed_new_buses                                                rider/date/commute                               \n",
       "Is405North_10_ride:I405HOV                                       rider/date/commute                               \n",
       "imputed_new_buses:I405HOV                                        rider/date/commute                               \n",
       "imputed_new_buses:Is405North_10_ride                             rider/date/commute                               \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     rider/date/commute                               \n",
       "imputed_new_buses                                                rider/date/commute                               \n",
       "imputed_new_buses:single_stop_10_ride                            rider/date/commute                               \n",
       "Is405North_10_ride:I405HOV                                       rider/date/commute                               \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     rider/date/commute                               \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   rider/date/commute                               \n",
       "imputed_new_buses                                                rider/date/commute                               \n",
       "imputed_new_buses:single_stop_10_ride                            rider/date/commute                               \n",
       "Is405North_10_ride:I405HOV                                       rider/date/commute                               \n",
       "imputed_new_buses:Is405North_10_ride:I405HOV                     rider/date/commute                               \n",
       "single_stop_10_ride:Is405North_10_ride:I405HOV                   rider/date/commute                               \n",
       "imputed_new_buses:single_stop_10_ride:Is405North_10_ride:I405HOV rider/date/commute                               "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "(TABLE_4 <- rbind(T4_M1,T4_M2,T4_M3,T4_M4,T4_M5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "2"
      ],
      "text/latex": [
       "2"
      ],
      "text/markdown": [
       "2"
      ],
      "text/plain": [
       "[1] 2"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "1 + 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "R",
   "language": "R",
   "name": "ir"
  },
  "language_info": {
   "codemirror_mode": "r",
   "file_extension": ".r",
   "mimetype": "text/x-r-source",
   "name": "R",
   "pygments_lexer": "r",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
